//assetManager/amGetAssetMaintenance
(function() {
	const response = {
		type: 'page',
		name: "amMaintenance",
		title: '待处理维修资产',
		"toolbar": [
			{
				"type": "button",
				"label": "刷新",
				"onEvent": {
					"click": {
						"actions": [
							{
								"actionType": "refresh"
							}
						]
					}
				}
			}
		],
		body:[
			{
				type: "crud",
				name: "amGetAssetMaintenance",
				syncLocation: false,
				api: {
					method: "post",
					url: "/assetManager/amGetAssetMaintenance",
					adaptor: function (payload, response) {
						if(payload.msg==="维修申请"){
							payload.msg="已更新维修申请列表";
						}

						return payload;
					}
				},
				//从响应中过滤出”正在进行“的维修申请
				"source": "${items | filter:isComplete:match:'正在进行'|filter:result:match:'运维维修失败'}",
				"autoFillHeight": true,
				loadDataOnce: true,
				columns:[
					{
						name: "id",
						label: "申请编号",
					},
					{
						name: "assetId",
						label: "资产编号"
					},
					{
						name: "applicantId",
						label: "申请人编号"
					},
					{
						name: "status",
						label: "申请时资产状态"
					},
					{
						name: "result",
						label: "当前维修进度"
					},
					{
						name: "isComplete",
						label: "维修申请状态"
					},
					{
						name: "handle",
						label: "下一步操作",
						type: "select",
						value: "4",
						options: [
							{
								"label": "联系供应商维修",
								"value": "1"
							},
							{
								"label": "因过保取消维修",
								"value": "2"
							},
							{
								"label": "过保但联系供应商维修",
								"value": "3"
							},
							{
								"label": "因其他原因无法维修",
								"value": "4"
							}
						],
					},
					{
						"type": "operation",
						"label": "操作",
						"width": 100,
						"buttons": [
							{
								"type": "button",
								"label": "提交维修方案",
								"actionType": "ajax",//运维人员完成维修
								"reload": "amGetAssetMaintenance", //请求完成后刷新amGetAssetMaintenance组件
								"api": {
									"method": "post",
									"url": "/assetManager/amUpdateAssetMaintenance",
									"data":{
										"assetMaintenanceId": "${id}",
										"result": "${handle}"
									},
									//当只剩最后一个记录的时候，再次发送审批请求后返回的status状态码为400，所以选择直接刷新
									adaptor: function (payload, response) {
										if(payload.msg==="维修申请"){
											payload.msg="已完成维修";
										}
										(function (){
											if(payload.status===400){
												payload.msg="所有维修都已处理!"
												window.location.reload();
											}
										})();
										return payload;
									}
								}
							}
						]
					}
				]


			}
		]

	}


	window.jsonpCallback && window.jsonpCallback(response);
})();
